package com.yanqu.road.server.manager.activity.hsisland.handler.impl;

import com.yanqu.road.entity.activity.hsisland.HsIslandExploreResult;
import com.yanqu.road.entity.activity.hsisland.HsIslandReward;
import com.yanqu.road.entity.activity.hsisland.HsIslandUserLog;
import com.yanqu.road.entity.activity.hsisland.config.HsIslandBuffConfig;
import com.yanqu.road.entity.activity.hsisland.config.HsIslandConfig;
import com.yanqu.road.entity.activity.hsisland.config.HsIslandGiftConfig;
import com.yanqu.road.entity.activity.hsisland.data.HsIslandEventData;
import com.yanqu.road.entity.activity.hsisland.enums.HsIslandUserLogTypeEnum;
import com.yanqu.road.server.manager.activity.hsisland.CrossHsIslandActivity;
import com.yanqu.road.server.manager.activity.hsisland.CrossHsIslandIsland;
import com.yanqu.road.server.manager.activity.hsisland.CrossHsIslandUser;
import com.yanqu.road.server.manager.activity.hsisland.handler.HsIslandIEventHandler;
import com.yanqu.road.server.manager.activity.hsisland.handler.param.HsIslandExploreHandlerReq;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

public class HsIslandEventRewardHandler implements HsIslandIEventHandler {

    /**
     * 探索后处理
     * @param req
     * @return
     */
    @Override
    public HsIslandExploreResult explore(HsIslandExploreHandlerReq req) {
        CrossHsIslandActivity activity = req.getActivity();
        HsIslandConfig config = activity.getConfig();
        HsIslandEventData eventData = req.getEventData();
        CrossHsIslandUser user = req.getUser();
        CrossHsIslandIsland island = req.getIsland();
        //事件注入坐标
        eventData.addPosition(req.getX(), req.getY());
        //按权重随机奖励
        HsIslandGiftConfig giftConfig = config.getWeightRandomGift();
        eventData.setGiftConfigId(giftConfig.getId());
        //获取奖励
        Property reward = PropertyHelper.parseNewStringToProperty(giftConfig.getReward());
        //获取积分
        long score = giftConfig.getScore();
        HsIslandReward islandReward = user.createReward(score, reward, null, eventData);
        //注入事件
        island.putEvent(eventData);
        //【圣柱奖励】事件探索完就完结
        island.finishEvent(eventData);
        //个人日志-圣柱馈赠事件
        HsIslandUserLog log = new HsIslandUserLog();
        log.setType(HsIslandUserLogTypeEnum.USER_LOG_TYPE_7.getType());
        log.setGiftConfigId(giftConfig.getId());
        log.setReward(islandReward);
        log.setTime(System.currentTimeMillis());
        user.addUserLog(log);
        //返回
        HsIslandExploreResult resp = new HsIslandExploreResult();
        resp.addEventData(eventData);
        resp.setReward(islandReward);
        return resp;
    }
}
